package com.jsbj.user.controller;


import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysDictData;
import com.jsbj.user.service.ISysDictDataService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 字典类型数据表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-dict-data")
@Api(value = "字典表查询接口", tags = "字典表查询接口")
//@ApiIgnore
public class SysDictDataController extends BaseController {

    @Autowired
    private ISysDictDataService sysDictDataService;

    @ApiOperation("根据dickey查询该租户下数据")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysDictData.class)})
    @PostMapping(value = "getDataByDictKey")
    public ResultBean<List<SysDictData>> getDataByDictKey(HttpServletRequest request, @RequestBody String inParam) {
        return new ResultBean<List<SysDictData>>(sysDictDataService.getDataByDictKey(request, inParam));
    }

    @ApiOperation(value = "添加字典类型")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<String> add(@RequestBody SysDictData sysDictData) {
        return sysDictDataService.add(sysDictData);
    }

    @ApiOperation(value = "删除")
    @ResponseBody
    @PostMapping("/delete")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean delete(@RequestParam String id) {
        return new ResultBean<Integer>(sysDictDataService.delete(id));
    }

    @ApiOperation("导出")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    @PostMapping("/export")
    public void export(@RequestBody String inParam, HttpServletResponse response) throws IOException {
        sysDictDataService.export(inParam, response);
    }

    @PostMapping("/getSecType")
    public List<SysDictData> getSecType() {
        return sysDictDataService.getSecType();
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @PostMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    public ResultBean<PageReq> getList(@RequestBody String inParam) {
        return new ResultBean<PageReq>(getPage(sysDictDataService.getList(inParam)));
    }

    @ApiOperation("字典数据列表(不分页)")
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "项目id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "dictKey", value = "字典类型", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "dicValue", value = "字典值", required = true)})
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = String.class)})
    @PostMapping("/selectDictDescByKeyAndValue")
    public ResultBean<String> selectDictDescByKeyAndValue(String dictKey, String dicValue){

        return new ResultBean(sysDictDataService.selectDictDescByKeyAndValue(dictKey,dicValue));
    }

    @GetMapping(value = "getOrgTypePageData")
    public ResultBean<List<SysDictData>> getOrgTypePageData() {
        return new ResultBean<List<SysDictData>>(sysDictDataService.getOrgTypePageData());
    }

    @GetMapping(value = "getDataByDictKeyOnly")
    public List<SysDictData> getDataByDictKeyOnly(@RequestParam String dictKey) {
        return sysDictDataService.getDataByDictKeyOnly(dictKey);
    }
}

